package com.qianyu.project.service.handler;

import com.alibaba.fastjson.JSON;
import com.qianyu.project.core.annotation.FlowHandler;
import com.qianyu.project.core.bean.FormAudit;
import com.qianyu.project.core.context.handler.FlowFinishedHandler;
import com.qianyu.project.entity.MaterialUsePlan;
import com.qianyu.project.service.IMaterialUsePlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author lyz
 * @date create in 2021/2/5 21:39
 */
@Component
@FlowHandler("material_use_plan")
public class MaterialUsePlanHandler implements FlowFinishedHandler {
    @Autowired
    private IMaterialUsePlanService service;


    @Override
    public void postAllowHandle(String jsonForm, FormAudit formAudit) {
        commonUpdate(jsonForm,formAudit,3);
    }

    @Override
    public void postRefuseHandle(String jsonForm, FormAudit formAudit) {
        commonUpdate(jsonForm,formAudit,2);
    }

    private void commonUpdate(String jsonForm,FormAudit formAudit,Integer approveStatus){
        MaterialUsePlan usePlan= JSON.parseObject(jsonForm,MaterialUsePlan.class);
        usePlan.setApproveStatus(approveStatus);
        service.updateById(usePlan);
    }

}
